home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / ast_text / faqs / tcl-faqs / part2 < prev    next >
Text File  |  1993-06-28  |  34KB  |  1,049 lines

  1. Newsgroups: comp.lang.tcl,comp.answers,news.answers
  2. Path: senator-bedfellow.mit.edu!enterpoop.mit.edu!gatech!howland.reston.ans.net!math.ohio-state.edu!sdd.hp.com!caen!malgudi.oar.net!chemabs!lvirden
  3. From: lwv26@cas.org (Larry W. Virden)
  4. Subject: FAQ: comp.lang.tcl Frequently Asked Questions (2/3)
  5.     (Last updated: June 16, 1993)
  6. Message-ID: <tcl.p2_740234997@cas.org>
  7. Followup-To: comp.lang.tcl
  8. Summary: A regular posting of the comp.lang.tcl Frequently Asked Questions 
  9.     (FAQ) and their answers.  This is the second of three parts.
  10.     This part covers the how-to questions and answers.
  11. Originator: lwv26@lwv26aws
  12. Keywords: tcl, expect, extended tcl, wish, tk
  13. Sender: lvirden@cas.org
  14. Supersedes: <tcl.p2_737658025@cas.org>
  15. Reply-To: lvirden@cas.org (Larry W. Virden)
  16. Organization: Chemical Abstracts Service
  17. References: <tcl.p1_740234997@cas.org>
  18. Date: Wed, 16 Jun 1993 12:50:38 GMT
  19. Approved: news-answers-request@MIT.Edu
  20. Expires: Wed, 28 Jul 1993 12:49:57 GMT
  21. Lines: 1025
  22. Xref: senator-bedfellow.mit.edu comp.lang.tcl:4758 comp.answers:1025 news.answers:9491
  23.  
  24. Archive-name: tcl-faq/part2
  25. Version: 3.3
  26. Last-modified: June 16, 1993
  27.  
  28. Please do not be offended if I neglect to acknowledge your contribution
  29. to this FAQ!  I sometimes forget to put an attribution in.  I especially
  30. try to add them if it appears that there is further experimentation or
  31. debugging being done though.
  32.  
  33.     For more information concerning Tcl (see "tcl-faq/part1") or
  34. (see "tcl-faq/part3").
  35.  
  36. Index of questions:
  37.  
  38. VIII. Questions on building Tcl and friends on your system
  39.     Q8A. Is there anywhere I can find help with the details of getting 
  40.         Tcl to work on my machine?
  41.     Q8B. When I am trying to build Tcl, the link step says that some 
  42.         of the functions Tcl needs are missing.
  43.     Q8C. Has anyone built Tcl 6 on an RS/6000 AIX 3.1? 
  44.     Q8D. Has anyone gotten Tcl to compile under HP-UX?
  45.     Q8E. Has anyone gotten Tcl to compile under VMS?
  46.     Q8F. What does it take to get Tcl to compile under SCO Unix?
  47.     Q8G. When I try to run the tclTest I get format and scan errors 
  48.         (NeXT, AIX, etc.)
  49.     Q8H. When I try to run Tcl V6 tclTest under Irix 4.0.1 I get
  50.         lots of errors.
  51.     Q8I. Does anyone else have problems with Tcl on a Cray?
  52.     Q8J. Does anyone know how to get Tk to run on a SparcBook or other
  53.         laptop with a limited number of colors?
  54.     Q8K. What does it take to get Tcl/Tk to compile on 386bsd/Linux 
  55.         or other POSIX/ANSI C systems not already supported?
  56.     Q8L. Can anyone help me build tcl 6.7 under NextStep 3.0?
  57.  
  58. IX.  How, in Tcl, can I XXX:
  59.     Q9A. get association lists or property lists?
  60.     Q9B. call one proc with the multi parameter value returned by 
  61.         another proc?
  62.     Q9C. pass an array into a proc?
  63.     Q9D. pipe output of a command back into a Tcl parsing procedure?
  64.     Q9E. merge extended Tcl into other programs such as wish or expect?
  65.     Q9F. delete a procedure from within a script?
  66.     Q9G. get parray to recognize an array variable I have created
  67.         via upvar?
  68.     Q9H. get more than 7 digits of double precision?
  69.     Q9I. grab the command line whenever a non-built-in call is made?
  70.     Q9J. get or set an environment variable?
  71.     Q9K. use numbers with leading zeroes?
  72.     Q9L. find the command line arguments to my application?
  73.     Q9M. put comments in my script, for example in a case statement?
  74.     Q9N. redirect stdin or stdout safely, including binary data?
  75.     Q9O. trap signals, and other more Unix specific functions?
  76.  
  77. X.  How, in Tk, can I XXX:
  78.     A. Question on starting Tk applications
  79.  
  80.     Q10.A.1. get my wish application to execute - I just get a wish prompt!
  81.     Q10.A.2. ,using a machine with less than 8 bit color, run?
  82.     Q10.A.3. set X11 resources for a wish application in an 
  83.         app-defaults file?
  84.     Q10.A.4. specify bitmap patterns on the command line instead of 
  85.         as a file name?
  86.     Q10.A.5. get a Motif user interface?
  87.     Q10.A.6. get an OpenLook user interface?
  88.  
  89.     B. Questions on Tk applications and the keyboard
  90.  
  91.     Q10.B.1. change the default class bindings?
  92.     Q10.B.2. delete a binding?
  93.     Q10.B.3. change a binding while it is being executed?
  94.     Q10.B.4. bind the arrow key on my Sun keyboard?
  95.     Q10.B.5. get root's mouse bindings to work in my Tk application?
  96.  
  97.     C. Questions on Tk and X11 interactions
  98.  
  99.     Q10.C.1. get an application to also use libXt?
  100.     Q10.C.2. change the X11 cursor?
  101.     Q10.C.3. raise or lower a window?
  102.     Q10.C.4. re-map a withdrawn window id?
  103.     Q10.C.5. use Tk in a subwindow of a non-Tk X11 application?
  104.  
  105.     D. Questions on Tk listboxes
  106.  
  107.     Q10.D.1. resize a listbox?
  108.     Q10.D.2. select two items that are not adjacent in the listbox at 
  109.         one time?
  110.     Q10.D.3. select items in more than one Tk listbox at a time?
  111.  
  112.     E. Other questions
  113.  
  114.     Q10.E.1. get the name of my own interpreter?
  115.     Q10.E.2. get -relief to work on my text widgets?
  116.     Q10.E.3. get output from a Tk canvas?
  117.     Q10.E.4. fill a canvas which is bounded by lines as opposed to a
  118.         shape like a polygon, oval, etc.?
  119.     Q10.E.5. create a scrollable window of buttons?
  120.     Q10.E.6. pack a text widget so that it can be resized interactively?
  121.     Q10.E.7. create a widget with an upper case name?
  122.  
  123. End of FAQ Index
  124.  
  125. ----------------------------------------------------------------------
  126.  
  127. ------------------------------
  128.  
  129. From: -VIII- Questions on building Tcl and friends on your system
  130. Subject: -Q8A- Is there anywhere I can find help with the details of 
  131.         getting Tcl to work on my machine?
  132.  
  133. A8A. Glad you asked!  Look in the Tcl distribution for the file called
  134. "porting.notes".  This will contain a collection of notes that various people
  135. have provided about porting Tcl to various machines and operating systems.
  136. There are also a file called "README" which should be read FIRST - before
  137. doing anything else with the code (this should always be one's first
  138. step with any package).  Finally, there is a "changes" file which details
  139. what has changed since the last release - be sure to read this to see
  140. what might need to change in your programs.
  141.  
  142. ------------------------------
  143.  
  144. From: -VIII- Questions on building Tcl and friends on your system
  145. Subject: -Q8B- When I am trying to build Tcl, the link step says that
  146.         some of the functions Tcl needs (such as strtoul and
  147.         strerror) are missing.
  148.  
  149. A8B. Did you run the "config" program first, by doing a "csh ./config" or
  150. equivalent?
  151.  
  152. Tcl includes equivalents for the following functions and include files
  153. which may not be found on some systems:
  154.  
  155. dirent.h       limits.h          stdlib.h         string.h
  156.  
  157. opendir.c      strerror.c     strstr.c         strtol.c        strtoul.c
  158.  
  159. strtod.c
  160.  
  161. ------------------------------
  162.  
  163. From: -VIII- Questions on building Tcl and friends on your system
  164. Subject: -Q8C- Has anyone built Tcl 6 on an RS/6000 AIX 3.1? 
  165.  
  166. A8C. See porting notes - especially the note about strtoul.
  167.  
  168. One user got Tcl to compile with a few minor source modifications
  169. (for example, duplicate case statements for errno and signal symbols in 
  170. tclUnixStr.c). 
  171.  
  172. A few other problems arose in the tests.  One is caused by AIX printf
  173. not formatting %#x and %#o correctly when the value to be printed is
  174. zero:  they print "0x0" and "00" instead of "0" and "0" respectively.
  175. This was reported as not a problem in earlier releases.  No fixes have
  176. been posted.
  177.  
  178. Finally, a problem occurs in open.test.  test 13.6 hangs because "cat"
  179. on the RS6000 is unbuffered.  A workaround is to change the execution
  180. of "cat" in open.test to do a "cat -u".
  181.  
  182. Dov Grobgeld <dov@menora.weizmann.ac.il> provided info on creating Tcl
  183. and Tk shared libraries under AIX 3.1.5:
  184.  
  185. For Tcl:
  186.  
  187. cc -o tkshar.o *.o -bE:tclshar.exp -bM:SRE -berok -lX11 -lm
  188. ar r libtclshr tclshar.o
  189.  
  190. For Tk:
  191.  
  192. cc -o tkshar.o *.o -bE:tkshar.exp -bM:SRE -berok -Ltcl -lX11 -lm -ltclshr
  193. ar r libtkshr tkshar.o
  194.  
  195. where tckshar.exp and tkshar.exp had lists of the external functions.
  196.  
  197. ------------------------------
  198.  
  199. From: -VIII- Questions on building Tcl and friends on your system
  200. Subject: -Q8D- Has anyone gotten Tcl to compile under HP-UX?
  201.  
  202. A8D. See the porting notes.
  203.  
  204. ------------------------------
  205.  
  206. From: -VIII- Questions on building Tcl and friends on your system
  207. Subject: -Q8E- Has anyone gotten Tcl to compile under VMS?
  208.  
  209. A8E. Information from jkimball@src.honeywell.com (John Kimball) on
  210. May 4, 1993 was that he had gotten Tcl 6.7 and Tk 3.2 ported to VMS
  211. 5.5.  See the catalog for the file information.
  212.  
  213. ------------------------------
  214.  
  215. From: -VIII- Questions on building Tcl and friends on your system
  216. Subject: -Q8F- What does it take to get Tcl to compile under SCO Unix?
  217.  
  218. A8F. Add a "#undef select" to tkEvent.c, and remove the reference to 
  219. TK_EXCEPTION around line 460 of main.c.
  220.  
  221. Tk uses its own scheme for allocating the border colors for its 3D
  222. widgets, which causes problems when running TK on a system with
  223. "PseudoColor" display class, and a 16-cell colormap.
  224.  
  225. If you can't go to eight bitplanes, you can instead start the server
  226. with a "-static" (Xsco) or "-analog" (Xsight) option, making the
  227. display class become "StaticColor".  This makes the entire colormap
  228. read-only, and it will return the color that most closely maps to the
  229. desired color as possible.
  230.  
  231. This information is from Keith Amann <Keith_Amann@stortek.com>
  232.  
  233. ------------------------------
  234.  
  235. From: -VIII- Questions on building Tcl and friends on your system
  236. Subject: -Q8G- When I try to run the tclTest I get format and scan errors 
  237.         (NeXT, AIX, etc.)
  238.  
  239. A8G. That's a problem (scanf/printf) many systems seem to have.  Don't
  240. worry too much about it - just don't use these 'advanced' features.  If
  241. you're hacking C, you'll have the same problems.
  242.  
  243. ------------------------------
  244.  
  245. From: -VIII- Questions on building Tcl and friends on your system
  246. Subject: -Q8H- When I try to run Tcl V6 tclTest under Irix 4.0.1 I get 
  247.         lots of errors.
  248.  
  249. A8H. There's a bug in the 4.0.1 optimizer that's fixed in 4.0.2.
  250. Compile tclVar.c using -O0 (no optimization).
  251.  
  252. ------------------------------
  253.  
  254. From: -VIII- Questions on building Tcl and friends on your system
  255. Subject: -Q8I- Does anyone else have problems with Tcl on a Cray?
  256.  
  257. A8I. See the porting notes for a set of changes mentioned.  Also,
  258. Booker C. Bense <benseb@grumpy.sdsc.edu> reports that version 3.0.1.6
  259. has some real problems with char pointers, causing Tcl to crash.  Using
  260. version 3.0.2.1, things are much better, except for a minor formatting
  261. problem and serious problems with scan.
  262.  
  263. ------------------------------
  264.  
  265. From: -VIII- Questions on building Tcl and friends on your system
  266. Subject: -Q8J- Does anyone know how to get Tk to run on a SparcBook or other
  267.         laptop with a limited number of colors?
  268.  
  269. A8J. On a SparcBook, if you start openwin (the OpenWindows server starting
  270. command) as:
  271.  
  272. openwin -dev "/dev/fb staticvis"
  273.  
  274. you get a static visual color model that Tk copes with better than the
  275. default.  Some things are ugly, but not as ugly as monochrome.
  276.  
  277. ------------------------------
  278.  
  279. From: -VIII- Questions on building Tcl and friends on your system
  280. Subject: -Q8K- What does it take to get Tcl/Tk to compile on 386bsd/Linux 
  281.         or other Posix/ANSI C systems not already supported?
  282.  
  283. A8K. Patches for 386BSD were posted to comp.lang.tcl back in Nov. 1992 to
  284. alt.sources.  See one of the ftp archive sites for this group for them.
  285. Basically, there were some setting of defines and a few places where 
  286. const char * had to be used in place of char *.  
  287.  
  288. ------------------------------
  289.  
  290. Subject: -Q8L- Can anyone help me build tcl 6.7 under NextStep 3.0?
  291.  
  292. A8L. Put #include <sys/time.h> near the top of tclUnixAZ.c.
  293. Thanks to Michael B. Johnson <wave@media.mit.edu>.
  294.  
  295. ------------------------------
  296.  
  297. From: -IX-  How, in Tcl, can I XXX:
  298. Subject: -Q9A- association lists or property lists?
  299.  
  300. A9A. Use Extended Tcl arrays or keyed lists.
  301.  
  302. For example, if you did a:
  303.  
  304. keylset ttyFields ttyName tty1a
  305. keylset ttyFields baudRate 57600
  306. keylset ttyFields parity strip
  307.  
  308. And then an "echo $ttyFields", you'd get:
  309.  
  310.     {ttyName tty1a} {baudRate 57600} {parity strip}
  311.  
  312. ------------------------------
  313.  
  314. From: -IX-  How, in Tcl, can I XXX:
  315. Subject: -Q9B- call one proc with the multi parameter value returned by 
  316.         another proc?
  317.  
  318. A9B. Assuming y requires multiple args and x returns multiple words, use 
  319.     Tcl's eval command "eval y [x]"
  320.  
  321. ------------------------------
  322.  
  323. From: -IX-  How, in Tcl, can I XXX:
  324. Subject: -Q9C- pass an array into a proc?
  325.  
  326. A9C. Use upvar rather than try to use global variables.
  327.  
  328.  
  329. # print elements of an array
  330. proc show arrayName {
  331.     upvar $arrayName myArray
  332.  
  333.     foreach element [array names myArray] {
  334.        puts stdout "${arrayName}($element) =  $myArray($element)"
  335.     }
  336. }
  337.  
  338. set arval(0) zero
  339. set arval(1) one
  340. show arval
  341.  
  342. Extended Tcl introduces a concept called keyed lists which are arrays
  343. made out of lists of key-value pairs and can be passed by value to routines,
  344. over networks, etc.
  345.  
  346. ------------------------------
  347.  
  348. From: -IX-  How, in Tcl, can I XXX:
  349. Subject: -Q9D- pipe output of a command back into a Tcl parsing 
  350.         procedure?
  351.  
  352. A9D. For example, to grep a pattern out of a range of files, one might
  353. do:
  354.  
  355. karl@NeoSoft.com (Karl Lehenbauer) writes:
  356.  
  357. set files [glob /home/cole/stats/*]
  358.  
  359. proc parseInfo { site } {
  360.    global files
  361.  
  362. #
  363. # site is chosen from a listbox earlier
  364. #
  365.    set in [open [concat "|/usr/bin/grep $site $files"] r]
  366.  
  367.    while {[gets $in line]>-1} {
  368.       puts stderr $line
  369.    }
  370.    catch {close $in}
  371. }
  372.  
  373. One thing:  the matching strings are _not_ returned in directory order.
  374.  
  375. But what if I want to check the return code AND use the output of 
  376. the command?  kennykb@dssv01.crd.ge.com (Kevin B. Kenny) writes:
  377.  
  378. if [catch {exec ls} data] {
  379.         # The exec got an error, and $errorCode has its termination status
  380. } else {
  381.         # The exec succeeded
  382. }
  383. # In any case, `data' contains all the output from the child process.
  384.  
  385. Note that Karl Lehenbauer adds that errorCode will be a list containing
  386. three elements, the string "CHILDSTATUS", the process ID of the child,
  387. and the exit status of the child.
  388.  
  389. ------------------------------
  390.  
  391. From: -IX-  How, in Tcl, can I XXX:
  392. Subject: -Q9E- merge extended Tcl into other programs such as wish or expect?
  393.  
  394. A9E. The latest version of extended Tcl, tclX 6.5c, has been enhanced to
  395. make it easier to incorporate into applications.
  396.  
  397. ------------------------------
  398.  
  399. From: -IX-  How, in Tcl, can I XXX:
  400. Subject: -Q9F- delete a procedure from within a script?
  401.  
  402. A9F. rename procedureName ""
  403.  
  404. ------------------------------
  405.  
  406. From: -IX-  How, in Tcl, can I XXX:
  407. Subject: -Q9G- get parray to recognize an array variable I have created
  408.         via upvar?
  409.  
  410. A9G. Right now (June, 1992) upvar doesn't allow you to attach to an
  411. individual element of an array.  This is considered a bug by 
  412. Mr. Ousterhout and has been place on a bug list.
  413.  
  414. ------------------------------
  415.  
  416. From: -IX-  How, in Tcl, can I XXX:
  417. Subject: -Q9H- get more than 7 digits of double precision ?
  418.  
  419. A9H. Modify the tclExpr.c module to use %lf instead of %g.
  420.  
  421. ------------------------------
  422.  
  423. From: -IX-  How, in Tcl, can I XXX:
  424. Subject: -Q9I- grab the command line whenever a non-built-in call is made?
  425.  
  426. A9I. The procedure "unknown" is called automatically with arguments 
  427. containing the command and its arguments for any command that couldn't be 
  428. found.  In fact, Tcl and Extended Tcl use this feature to provide demand
  429. loaded commands, and even entire libraries.
  430.  
  431. So by modifying the unknown procedure you can provide your own extended
  432. functionality, or even remove the demand loading capability if you so
  433. desire.
  434.  
  435. ------------------------------
  436.  
  437. From: -IX-  How, in Tcl, can I XXX:
  438. Subject: -Q9J- get or set an environment variable?
  439.  
  440. A9J. By using something like the following.
  441.  
  442. set olddisplay $env(DISPLAY)
  443. set env(DISPLAY) unix:0
  444.  
  445. Thanks to "Joel Fine" <joel@cs.berkeley.edu> for the answer.
  446.  
  447. ------------------------------
  448.  
  449. From: -IX-  How, in Tcl, can I XXX:
  450. Subject: -Q9K- use numbers with leading zeroes?
  451.  
  452. A9K. Dave Morriss was recently having problems because he was trying
  453. to do something like:
  454.  
  455. set index [expr [exec date +%W]%[llength $pop_server_list]]
  456.  
  457. but during the 9th and 9th week of the year, he got errors - 08 and 09
  458. are not valid octal numbers in Tcl.
  459.  
  460. Some of the solutions provided were:
  461.  
  462. From George A. Howlett <gah@att.com>, we got:
  463.  
  464. set wknum [format "%g" [exec date +%W]]
  465. set index [expr [exec $wknum%[llength $pop_server_list]]
  466.  
  467. From Fred Feirtag <feirtag@wave.nrl.navy.mil> :
  468.  
  469. set index [expr (1[exec date +%W]-100)%[llength $pop_server_list]]
  470.  
  471. From Dan R. Schenck <schendr@Texaco.COM>:
  472.  
  473. set index [expr [string trimleft [exec date +%W] 0]%[llength $pop_server_list]]
  474.  
  475. ------------------------------
  476.  
  477. From: -IX-  How, in Tcl, can I XXX:
  478. Subject: -Q9L- find the command line arguments to my application?
  479.  
  480. A9L.  If you are using extended Tcl or Expect, you will find the parameters in
  481. the Tcl variable argv as a list.  Note that in extended Tcl, the name of 
  482. the program is in the Tcl variable programName and NOT in argv[0].  Thanks to
  483. brad@NeoSoft.com (Brad Morrison) and bachww@rtsg.mot.com (Bud Bach) for
  484. this answer.
  485.  
  486. ------------------------------
  487.  
  488. From: -IX-  How, in Tcl, can I XXX:
  489. Subject: -Q9M- put comments in my script, for example in a case statement?
  490.  
  491. A9M. You can't have comments where you have them.  Move the comments inside
  492. of the "{" for the case that you want.  Your code should read:
  493.  
  494. case 1 {
  495.   -1    {
  496.         #
  497.         # Cannot find information sought
  498.         #
  499.         exit 2
  500.         }
  501.    0    {
  502.         #
  503.         # Error in arguments
  504.         #
  505.         exit 1
  506.         }
  507.    default    {
  508.         #
  509.         # Desired information found
  510.         #
  511.         exit 0
  512.         }
  513. }
  514.  
  515. Thanks to gwlester@cpu.com (Gerald W. Lester).
  516.  
  517. ------------------------------
  518.  
  519. From: -IX-  How, in Tcl, can I XXX:
  520. Subject: -Q9N- redirect stdin or stdout safely, including binary data?
  521.  
  522. A9N. With Extended Tcl you can safely do stuff like:
  523.  
  524.         set infp [open "|compress -dc $fileName"]
  525.         set outfp [open "|gzip -c $newFileName" w]
  526.  
  527.         copyfile $infp $outfp
  528.  
  529. Thanks to karl@NeoSoft.com (Karl Lehenbauer) for the code example.
  530.  
  531. ------------------------------
  532.  
  533. From: -IX-  How, in Tcl, can I XXX:
  534. Subject: -Q9O- trap signals, and other more Unix specific functions?
  535.  
  536. A9O. Extended Tcl offers many of these types of functions.  For instance,
  537. extended Tcl has the 'signal' command:
  538.  
  539.         signal action siglist [command]
  540.  
  541.         where action is one of "default", "ignore", "error", "trap", "get",
  542.         plus the POSIX "block" and "unblock" actions (available only on
  543.         POSIX systems, of course).  Siglist is a list of either the symbolic
  544.         or numeric Unix signal (the SIG prefix is optional).  Command is your
  545.         error handler (or a simple {puts stdout "Don't press *that* key!"}  :-)
  546.  
  547. "trap" does what you expect, and I find "error" and "get" to be
  548. extremely useful in interactive programs which demand keyboard
  549. traversal.
  550.  
  551. Extended Tcl also has things like fork, etc.
  552.  
  553. Answer by brad@NeoSoft.com (Brad Morrison).
  554.  
  555. ------------------------------
  556.  
  557. From: -X-  How, in Tk, can I XXX:
  558. Subject: -Q10.A.1- get my wish application to execute - I just get a
  559.         wish prompt!  Or I just get error msgs about permission
  560.         denied, not found, etc.
  561.  
  562. A10.A.1. Most systems require a full pathname to the interpreter.  
  563. So you cannot start a wish script out as 
  564.  
  565. #! wish -f
  566.  
  567. Likewise, many Unix systems have a maximum length of characters that you can
  568. put on a #! line.  If you exceed this, you do not get the behaviour you
  569. expect.  So do not try to put something like:
  570.  
  571. #! /projects/somethingbig/bin/sun4/wish -f
  572.  
  573. followed by your wish code.  Keep the lines short - under 30 characters is
  574. recommended.
  575.  
  576. ------------------------------
  577.  
  578. From: -X-  How, in Tk, can I XXX:
  579. Subject: -Q10.A.2- ,using a machine with less than 8 bit color, run?
  580.  
  581. A10.A.2. Tk doesn't behave very well with less than 8-bit color screens.  To
  582. try to use it, find all the places in the Tk/wish source where 
  583. DefaultDepthOfScreen is invoked to test the number of bit-planes.  Change all
  584. of these to pretend there is just 1 bit-plane, or call a procedure which
  585. monitors a Tcl variable so that it is configurable, and you should be okay.
  586.  
  587. Another alternative is to see if the server you are using has alternative
  588. visual / color models, such as static visual, etc.  One of the alternatives
  589. may allow Tk to work better.
  590.  
  591. Thanks to "Nathaniel Borenstein" <nsb@thumper.bellcore.com> for this info!
  592.  
  593. ------------------------------
  594.  
  595. From: -X-  How, in Tk, can I XXX:
  596. Subject: -Q10.A.3- set X11 resources for a wish application in an 
  597.         app-defaults file?
  598.  
  599. A10.A.3. Read the documentation for the option command.
  600. Then you should consider something like the following - assume the program
  601. name is xwf.
  602.  
  603. The following are two general purpose functions to put into a library:
  604.  
  605. # envVal envValName
  606. #   Looks up the envValName environment variable and returns its
  607. #   value, or {} if it does not exists
  608. proc envVal {envValName} {
  609.   global env
  610.   if [info exists env($envValName)] {return $env($envValName)} {return {}}
  611. }
  612.  
  613. # loadAppDefaults classNameList ?priority?
  614. #   Searches for the app-default files corresponding to classNames in
  615. #   the order specified by X Toolkit Intrinsics, and loads them with
  616. #   the priority specified (default: startupFile).
  617. proc loadAppDefaults {classNameList {priority startupFile}} {
  618.   set filepath "[split [envVal XUSERFILESEARCHPATH] :] \
  619.         [envVal XAPPLRESDIR] \
  620.         [split [envVal XFILESEARCHPATH] :] \
  621.         /usr/lib/X11"
  622.   foreach i $classNameList {
  623.     foreach j $filepath {
  624.       if {[file exists $j/$i]} {
  625.     option readfile $j/$i $priority; break
  626.       }
  627.     }
  628.   }
  629. }
  630.  
  631. # Now, here is what you would put into xwf:
  632.  
  633. option add Tk.BoldFont "*-lucida sans-Bold-R-Normal-*-100-*" widgetDefault
  634. loadAppDefaults {xwf XWF} userDefault
  635.  
  636. This sets a program default, then load any defaults specified in the user's
  637. default resources and finally any site or general app-defaults resource.  
  638. Of course, you would want to add some xwf command line handling to allow 
  639. the user to override things at execution time.
  640.  
  641. ------------------------------
  642.  
  643. From: -X-  How, in Tk, can I XXX:
  644. Subject: -Q10.A.4- specify bitmap patterns on the command line instead of 
  645.         just as a file name?
  646.  
  647. A10.A.4. You can not, at least as of June, 1992.
  648.  
  649. ------------------------------
  650.  
  651. From: -X-  How, in Tk, can I XXX:
  652. Subject: -Q10.A.5- get a Motif user interface?
  653.  
  654. A10.A.5. Tk does not currently use the Xt toolkit, so a strict adherence
  655. to Motif via the libXm.a routines is not possible.  However, the authors
  656. of Tk prefer the Motif style of user interface, so you will find that Tk
  657. makes quite an attempt to implement a Motif-like interface.
  658.  
  659. ------------------------------
  660.  
  661. From: -X-  How, in Tk, can I XXX:
  662. Subject: -Q10.A.6- get an OpenLook user interface?
  663.  
  664. A10.A.6. Unfortunately, Tk does not currently use either XView or Xt based
  665. widgets in its user interface, so an OpenLook compliant (or even
  666. similar) interface is probably not easily achievable in the near future.
  667.  
  668. ------------------------------
  669.  
  670. From: -X-  How, in Tk, can I XXX:
  671. Subject: -Q10.B.1- change the default class bindings?
  672.  
  673. A10.B.1. All default class bindings for Tk widgets are initialized in
  674. $tk_library/tk.tcl.  Use this file as a guide to implement new
  675. bindings.  For instance, the following code duplicates Button 1's
  676. drag-select facility in Button 3 for all listboxes:
  677.  
  678. bind Listbox <3> {%W select from [%W nearest %y]}
  679. bind Listbox <B3-Motion> {%W select to [%W nearest %y]}
  680.  
  681. ------------------------------
  682.  
  683. From: -X-  How, in Tk, can I XXX:
  684. Subject: -Q10.B.2- delete a binding?
  685.  
  686. A10.B.2. Give an empty-string command to the "bind" invocation.  For
  687. example, to disable the Delete key in all entry fields:
  688.  
  689.     bind Entry <Delete> {}
  690.  
  691. ------------------------------
  692.  
  693. From: -X-  How, in Tk, can I XXX:
  694. Subject: -Q10.B.3- change a binding while it is being executed?
  695.  
  696. A10.B.3. As of June, 1992, this was not a safe thing to do in Tk.  It was
  697. put on the bug list by John Ousterhout to be fixed in a future version.
  698.  
  699. The solution for now is not to change the bindings, but to change
  700. something in the code they execute.  For example, keep a state variable
  701. that indicates which binding you'd like, but always have the binding
  702. call a given procedure.  Then that procedure checks the variable and
  703. executes one piece of code or another.  Or, you could just make the
  704. binding's command "eval $cmd" and then change the variable "cmd"
  705. depending on your application's state.
  706.  
  707. ------------------------------
  708.  
  709. From: -X-  How, in Tk, can I XXX:
  710. Subject: -Q10.B.4- bind the arrow key on my Sun keyboard?
  711.  
  712. A10.B.4. You have to call it <Left> rather than <R10>.  Under X11, keys are
  713. referred to by their keysym.  One can use either xmodmap -pk or the xev
  714. program to determine what the keysym a particular key on a keyboard is
  715. currently generating.
  716.  
  717. If the keysym that is being used is not known by Tk, you may have to edit
  718. its ks_names.h file.  There is a note in this file that indicates that
  719. one should not edit it - but this is where the keysym must be for it to
  720. be recognized.
  721.  
  722. Thanks to Wayne Christopher <faustus@ygdrasil.CS.Berkeley.EDU> for this
  723. note.
  724.  
  725. ------------------------------
  726.  
  727. From: -X-  How, in Tk, can I XXX:
  728. Subject: -Q10.B.5- get root's mouse bindings to work in my Tk application?
  729.  
  730. A10.B.5. Some window managers, such as mwm, define mouse button bindings
  731. which cause Tk some problems.  Try saving off the window manager's startup
  732. file (something like /.mwmrc for instance) and then copy in a startup
  733. file from a login id that works.  Thanks to brad@NeoSoft.com (Brad Morrison)
  734. for this invaluable tip!
  735.  
  736. ------------------------------
  737.  
  738. From: -X-  How, in Tk, can I XXX:
  739. Subject: -Q10.C.1- get an application to also use libXt?
  740.  
  741. A10.C.1. Tk2.1 and Xt have different X connections, and XtAppNextEvent will
  742. block is there is nothing coming from the X connection.  One way
  743. of fixing this is get the connection number of Tk using
  744.  
  745.    ConnectionNumber(Tk_Display(tk_window));
  746.  
  747. and using XtAddInput to register this with the Xt event handler.  The
  748. callback procedure for XtAddInput wrapper procedure that runs
  749. Tk_OneEvent(1).  There might be problems with Tk file sources which
  750. aren't registered with Xt.
  751.  
  752. Thanks to joe@astro.as.utexas.edu (Joe Wang) for this information.
  753.  
  754. ------------------------------
  755.  
  756. From: -X-  How, in Tk, can I XXX:
  757. Subject: -Q10.C.2- change the X11 cursor?
  758.  
  759. A10.C.2. Here is a tip from mgc@cray.com (M. G. Christenson).
  760.  
  761. Look at /usr/include/X11/cursorfont.h for a list of available cursors.
  762. You can use the names in there by removing the 'XC_'.  
  763.  
  764. Here's a little proc I use to make my entire application go 'busy'
  765. while it's doing something. Just call it with the commands you want to
  766. execute, and the watch cursor will be displayed for the time it takes
  767. the commands to complete.  Note that any new windows will have their
  768. normal cursor.
  769.  
  770. proc busy {cmds} {
  771.     global errorInfo
  772.  
  773.     set busy {.app .root}
  774.     set list [winfo children .]
  775.     while {$list != ""} {
  776.     set next {}
  777.     foreach w $list {
  778.         set class [winfo class $w]
  779.         set cursor [lindex [$w config -cursor] 4]
  780.         if {[winfo toplevel $w] == $w || $cursor != ""} {
  781.         lappend busy [list $w $cursor]
  782.         }
  783.         set next [concat $next [winfo children $w]]
  784.     }
  785.     set list $next
  786.     }
  787.  
  788.     foreach w $busy {
  789.     catch {[lindex $w 0] config -cursor watch}
  790.     }
  791.  
  792.     update idletasks
  793.  
  794.     set error [catch {uplevel eval [list $cmds]} result]
  795.     set ei $errorInfo
  796.  
  797.     foreach w $busy {
  798.     catch {[lindex $w 0] config -cursor [lindex $w 1]}
  799.     }
  800.  
  801.     if $error {
  802.     error $result $ei
  803.     } else {
  804.     return $result
  805.     }
  806. }
  807.  
  808. ------------------------------
  809.  
  810. From: -X-  How, in Tk, can I XXX:
  811. Subject: -Q10.C.3- raise or lower a window?
  812.  
  813. A10.C.3. This is on the (semi-infinite) list of things to be done in the future.
  814. If you have the time, please go ahead and add it and submit the code and all
  815. will be grateful.
  816.  
  817. ------------------------------
  818.  
  819. From: -X-  How, in Tk, can I XXX:
  820. Subject: -Q10.C.4- re-map a withdrawn window id?
  821.  
  822. A10.C.4. Use wm deiconify <windowid>.
  823.  
  824. ------------------------------
  825.  
  826. From: -X-  How, in Tk, can I XXX:
  827. Subject: -Q10.C.5- use Tk in a subwindow of a non-Tk X11 application?
  828.  
  829. A10.C.5. From faustus@ygdrasil.CS.Berkeley.EDU (Wayne A. Christopher):
  830.  
  831. [C]reate the Tk toplevel window but don't map it (wm withdraw).  Then
  832. re-parent the window to be a subwindow of your other one and then map
  833. it.  I have done this when the Tk application is a separate process,
  834. but if it's the same process I think you will get into trouble with the
  835. event loop, since each toolkit wants control.
  836.  
  837. ------------------------------
  838.  
  839. From: -X-  How, in Tk, can I XXX:
  840. Subject: -Q10.D.1- resize a listbox?
  841.  
  842. A10.D.1. Use wm min/maxsize - in a uniform manner.  Here is a resizable listbox:
  843.  
  844.         #!/usr/local/bin/wish -f
  845.         wm minsize . 20 20
  846.         wm maxsize . 1152 900
  847.         pack append . [listbox .l -borderwidth 2 -relief raised] {expand fill}
  848.  
  849. Doing the same with the text widget brings its resizing under control too.
  850.  
  851. Thanks to "John C Ellson" <ellson@ontap.att.com).
  852.  
  853. ------------------------------
  854.  
  855. From: -X-  How, in Tk, can I XXX:
  856. Subject: -Q10.D.2- select two items that are not adjacent in the listbox at 
  857.         one time?
  858.  
  859. A10.D.2.  See Marc R. Ewing's Listbox.patch for a way to modify Tk to allow
  860. selection of non-contiguous entries.
  861.  
  862. ------------------------------
  863.  
  864. From: -X-  How, in Tk, can I XXX:
  865. Subject: -Q10.D.3- select items in more than one Tk listbox at a time?
  866.  
  867. A10.D.3. The default for Tk's listbox widget exports its selection as the
  868. X selection.  There can only be one of these at a time.
  869.  
  870. To turn off this behavior in Tk, use the -exportselection false when
  871. you create the listbox.  Or, use the
  872.  
  873. option add *Listbox.exportselection false
  874.  
  875. command in the beginning of your script.
  876.  
  877. Thanks to David Herron <david@twg.com> for this tip.
  878.  
  879. ------------------------------
  880.  
  881. From: -X-  How, in Tk, can I XXX:
  882. Subject: -Q10.E.1- get the name of my own interpreter?
  883.  
  884. A10.E.1. gah@att.com (George A. Howlett) points us to the winfo manual
  885. page - winfo name . gets the name of the current application.
  886.  
  887. ------------------------------
  888.  
  889. From: -X-  How, in Tk, can I XXX:
  890. Subject: -Q10.E.2- get -relief to work on my text widgets?
  891.  
  892. A10.E.2. From Owen Rees <rtor@ansa.co.uk>, we find out that we must:
  893.  
  894. "[m]ake the border width non-zero as in"
  895.  
  896.    text .t -width 20 -height 20 -relief sunken -borderwidth 4
  897.  
  898. ------------------------------
  899.  
  900. From: -X-  How, in Tk, can I XXX:
  901. Subject: -Q10.E.3- get output from a Tk canvas?
  902.  
  903. A10.E.3. The latest Tk has a save suboption on canvas which allows one
  904. to create a file describing the canvas.  The default output is Encapsulated
  905. Postscript, but there is an xpm3 suboption as well.
  906.  
  907. ------------------------------
  908.  
  909. From: -X-  How, in Tk, can I XXX:
  910. Subject: -Q10.E.4- fill a canvas which is bounded by lines as opposed to a
  911.         shape like a polygon, oval, etc.?
  912.  
  913. A10.E.4. No, you have to at least use a polygon if you want to fill an area
  914. bounded by some lines.
  915.  
  916. ------------------------------
  917.  
  918. From: -X-  How, in Tk, can I XXX:
  919. Subject: -Q10.E.5- create a scrollable window of buttons?
  920.  
  921. A10.E.5. There are at least two ways to do this.  First, there is a hypertext
  922. widget that one can get from the Tcl User Contributed Code Archive (see
  923. comp.lang.tcl FAQ part 3 for details) which provides such a facility.
  924. And here is some sample code from 
  925. "Michael Moore" <mdm@stegosaur.cis.ohio-state.edu> which shows a way to 
  926. do this using just Tk.
  927.  
  928. #! /bin/wish -f
  929. #
  930. # This demonstrates how to create a scrollable canvas with mutliple
  931. # buttons.
  932. #
  933. # Author : Michael Moore
  934. # Date   : November 17, 1992
  935. #
  936.  
  937. #
  938. # This procedure obtains all the items with the tag "active"
  939. # and prints out their ids.
  940.  
  941. proc multi_action {} {
  942.     set list [.frame.canvas find withtag "active"]
  943.     puts stdout "Active Item Ids : "
  944.     foreach item $list {
  945.     puts stdout $item
  946.     }
  947. }
  948.  
  949. # This simulates the toggling of a command button...
  950. # Note that it only works on a color display as is right now
  951. # but the principle is the same for b&w screens.
  952. proc multi_activate {num id} {
  953.     
  954.     set tags [.frame.canvas gettags $id]
  955.     if {[lsearch $tags "active"] != -1} {
  956.     .frame.canvas dtag $id "active"
  957.     .frame.canvas.button$num configure \
  958.         -background "#060" \
  959.         -activebackground "#080" 
  960.     } else {
  961.     .frame.canvas addtag "active" withtag $id
  962.     .frame.canvas.button$num configure \
  963.         -background "#600" \
  964.         -activebackground "#800"
  965.     }
  966.  
  967. proc setup {} {
  968.      frame .frame
  969.  
  970.      scrollbar .frame.scroll \
  971.          -command ".frame.canvas yview" \
  972.          -relief raised
  973.  
  974.      canvas .frame.canvas \
  975.          -yscroll ".frame.scroll set" \
  976.          -scrollregion {0 0 0 650} \
  977.          -relief raised \
  978.      -confine false \
  979.      -scrollincrement 25
  980.  
  981.      pack append .frame \
  982.          .frame.scroll    {left frame center filly} \
  983.          .frame.canvas    {left frame center fillx filly}
  984.  
  985.      pack append .\
  986.          .frame   {left frame center fillx filly}
  987.  
  988.      button .frame.canvas.action  \
  989.          -relief raised \
  990.          -text "Action" \
  991.      -command "multi_action"
  992.      .frame.canvas create window 1 25 \
  993.      -anchor w \
  994.          -window .frame.canvas.action
  995.      for {set i 2} {$i < 26} {incr i} {
  996.      button .frame.canvas.button$i  \
  997.         -relief raised \
  998.         -background "#060" \
  999.         -foreground wheat \
  1000.         -activebackground "#080" \
  1001.         -activeforeground wheat \
  1002.         -text "Button $i" 
  1003.      set id [.frame.canvas create window 1 [expr $i*25] \
  1004.         -anchor w \
  1005.         -window .frame.canvas.button$i]
  1006.      .frame.canvas.button$i configure \
  1007.         -command "multi_activate $i $id"
  1008.     }
  1009. }
  1010.  
  1011. setup
  1012.  
  1013. ------------------------------
  1014.  
  1015. From: -X-  How, in Tk, can I XXX:
  1016. Subject: -Q10.E.6- pack a text widget so that it can be resized interactively?
  1017.  
  1018. A10.E.6. From Spencer W. Thomas <spencer@med.umich.edu> we find that we need to:
  1019.  
  1020. wm minsize . 0 0
  1021. text .text
  1022. pack append . .text {fill expand}
  1023.  
  1024. ------------------------------
  1025.  
  1026. From: -X-  How, in Tk, can I XXX:
  1027. Subject: -Q10.E.7- create a widget with an upper case name?
  1028.  
  1029. A10.E.7. During a recent revision of Tk, things were changed so that names
  1030. beginning with a capital letter are reserved for class names.  Specific
  1031. instances of widgets must begin with a lower case letter.  This enables
  1032. X11 resource definitions to distinguish between a class and instance.
  1033.  
  1034. ------------------------------
  1035.  
  1036. End of comp.lang.tcl Frequently Asked Questions (2/3)
  1037. *****************************************************
  1038. -- 
  1039. :s 
  1040. :s Larry W. Virden                 INET: lvirden@cas.org
  1041. :s Personal: 674 Falls Place,   Reynoldsburg, OH 43068-1614
  1042. -- 
  1043. :s 
  1044. :s Larry W. Virden                 INET: lvirden@cas.org
  1045. :s Personal: 674 Falls Place,   Reynoldsburg, OH 43068-1614
  1046.